<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>vsftp 利用mysql 验证虚拟账户 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>vsftp 利用mysql 验证虚拟账户</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/FTP/">FTP</a>
			</span>
		
	</div>

	

	
		<h2 id="安装vsftpd"><a href="#安装vsftpd" class="headerlink" title="安装vsftpd"></a>安装vsftpd</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">yum install -y  vsftpd</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;编辑vsftpd.conf</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line">listen=YES</div><div class="line">connect_from_port_20=YES</div><div class="line">pasv_enable=YES</div><div class="line">tcp_wrappers=YES</div><div class="line">local_enable=YES</div><div class="line">chroot_local_user=yes</div><div class="line">anonymous_enable=NO</div><div class="line">guest_enable=YES</div><div class="line">guest_username=vsftpdguest</div><div class="line">user_config_dir=/etc/vsftpd/vsftpd_user_conf</div><div class="line">pam_service_name=/etc/pam.d/vsftpd</div><div class="line">dirmessage_enable=YES</div><div class="line">idle_session_timeout=600</div><div class="line">check_shell=NO</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;创建一个虚拟用户映射系统用户    </p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">useradd –s /sbin/nologin vsftpdguest</div></pre></td></tr></table></figure>
<h2 id="安装-mysql"><a href="#安装-mysql" class="headerlink" title="安装 mysql"></a>安装 mysql</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;具体步骤参考 <a href="https://hcldirgit.github.io/2017/07/29/1.%20Mysql%E5%AE%89%E8%A3%85/" target="_blank" rel="external">MySQL安装</a></p>
<h2 id="安装-pam-mysql"><a href="#安装-pam-mysql" class="headerlink" title="安装 pam-mysql"></a>安装 pam-mysql</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pam-mysql/pam-mysql/0.7RC1/pam_mysql-0.7RC1.tar.gz</div><div class="line">tar zxvf  pam_mysql-0.7RC1.tar.gz</div><div class="line"><span class="built_in">cd</span> pam_mysql-0.7RC1</div><div class="line">./configure --with-mysql=/usr/<span class="built_in">local</span>/mysql --with-pam=/usr --with-pam-mods-dir=/usr/lib</div><div class="line">make &amp;&amp; make install</div></pre></td></tr></table></figure>
<h2 id="创建vsftp-库和相关的表并授权"><a href="#创建vsftp-库和相关的表并授权" class="headerlink" title="创建vsftp 库和相关的表并授权"></a>创建vsftp 库和相关的表并授权</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&gt;create database vsftp;</div><div class="line">&gt;use vsftp ;</div><div class="line">&gt;create table users ( name char(16) binary ,passwd char(125) binary ) ;</div><div class="line">&gt;insert into users (name,passwd) values (<span class="string">'test001'</span>,password(<span class="string">'123456'</span>));</div><div class="line">&gt;insert into users (name,passwd) values (<span class="string">'test002'</span>,password(<span class="string">'234567'</span>));</div><div class="line">&gt;grant select on vsftp.users to vsftpdguest@localhost identified by <span class="string">'vsftpdguest'</span>;</div></pre></td></tr></table></figure>
<h2 id="创建虚拟账户的配置文件"><a href="#创建虚拟账户的配置文件" class="headerlink" title="创建虚拟账户的配置文件"></a>创建虚拟账户的配置文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">mkdir /etc/vsftpd/vsftpd_user_conf </div><div class="line"><span class="built_in">cd</span>  /etc/vsftpd/vsftpd_user_conf</div><div class="line">vim test001</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">local_root=/ftp/        </div><div class="line">write_enable=YES</div><div class="line">virtual_use_local_privs=YES</div><div class="line">chmod_enable=YES</div></pre></td></tr></table></figure>
<h2 id="编辑验证文件"><a href="#编辑验证文件" class="headerlink" title="编辑验证文件"></a>编辑验证文件</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim  /etc/pam.d/vsftpd</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;内容如下</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#%PAM-1.0</span></div><div class="line">auth required /usr/lib/pam_mysql.so user=vsftpdguest passwd=vsftpdguest host=localhost db=vsftp table=users usercolumn=name passwdcolumn=passwd crypt=2</div><div class="line">account required /usr/lib/pam_mysql.so user=vsftpdguest passwd=vsftpdguest host=localhost db=vsftp table=users usercolumn=name passwdcolumn=passwd crypt=2</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果不想使用mysql也可以使用文件的形式来搞虚拟账号，请参考<a href="https://hcldirgit.github.io/2017/08/02/2.%20vsftp%E9%83%A8%E7%BD%B2%E5%92%8C%E4%BC%98%E5%8C%96/" target="_blank" rel="external">vsftp部署和优化</a></p>

	

	
		<span class="different-posts"><a href="/2017/10/12/FTP/4. vsftp 利用mysql 验证虚拟账户/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
